package com.tgy.util;

/**
 * @Author: tgy
 * @Date: 2020-08-28 09:17
 */
public abstract class AbstractList<E> implements List<E> {

    protected int size;


    @Override
    public int size() {
        return size;
    }

    @Override
    public boolean isEmpty() {

        return size ==  0;
    }

    @Override
    public void add(E element) {

        add(size,element);
    }

    @Override
    public boolean contains(E element) {

        return indexof(element) != NOT_FOUND_ELEMENT;
    }


    protected void checkIndex(int index){

        if (index < 0 || index >= size){

            throw new IndexOutOfBoundsException();
        }

    }

    protected void checkAddIndex(int index) {

        if (index < 0 || index > size ){

            throw new IndexOutOfBoundsException();
        }
    }
}
